﻿
@{
    var cate = ViewData["cate"] as article_category;
    ViewData["Title"] = cate.category_name;
    var page = ViewData["page"] as PageModel;
    var list = ViewData["list"] as List<article>;
    var users = ViewData["users"] as List<WqUser>;
}

@*分页查看预测历史的列表*@

<style type="text/css">
    .margin-top-10 {
        height: 10px;
    }

    .bztr {
        cursor: pointer;
        height: 30px;
        line-height: 30px;
    }
</style>

<div class="margin-top-10"></div>
<div class="margin-top-10"></div>
<div class="margin-top-10"></div>

<div class="row">
    <div class="col-sm-6 col-md-offset-3">
        <form role="form" class="form-inline">
            <div class="form-group-sm">
                <input type="text" class="form-inline" id="key" placeholder="请输入标题或者关键字搜索" />
                <a href="javascript:;" id="btn-search">
                    <span class="btn btn-primary btn-xs" onclick="searchBzjp()">查找</span>
                </a>
            </div>
        </form>
    </div>
</div>

<div class="margin-top-10"></div>
<div class="margin-top-10"></div>
<div class="margin-top-10"></div>

<div class="row">
    <div class="col-md-12">
        <table class="table table-responsive table-hover">
            <thead>
                <tr>
                    <td>标题</td>
                    <td>关键字</td>
                    <td>作者</td>
                    <td>发布时间</td>
                </tr>
            </thead>
            <tbody>
                @{
                    foreach (var item in list)
                    {
                        var user = users.FirstOrDefault(x => x.Id == item.uid) ?? new WqUser();
                        <tr class="bztr" onclick="javascript:location.href='@Url.Action("detail", new { id = item.id})'">
                            <td>@item.title</td>
                            <td>@item.keywords</td>
                            <td>@user.NickName</td>
                            <td>@item.create_time.ToLocalTime().ToString("yyyy-MM-dd HH:mm")</td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
</div>

@Html.Partial("Pagination", page)

@section Scripts{
    <script type="text/javascript">
        $(function () {
            $("#key").focus();
            $('#key').bind('keypress', function (event) {
                if (event.keyCode == "13") {
                    searchBzjp();
                }
            });
        })

        // 搜索预测历史
        function searchBzjp() {
            var key = $("#key").val();
            if (key == '')
                location.href = '@Url.Action("list")';
            else {
                var url = '@Url.Action("list",new { id = cate.id })' + '?search=' + key;
                $('#btn-search').attr("href", url);
                $('#btn-search').click();
            }
        }
    </script>
}

